package com.lins.msm;

import com.alibaba.druid.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author linshuo
 * @Date 2022/11/17 16:04
 */
@RestController
@RequestMapping("redis")
public class RedisDemo {

    @Autowired
    public RedisTemplate<String,String> redisTemplate;

    @RequestMapping("t1")
//    @Nullable
    public void t1(){
//        String code = redisTemplate.opsForValue().get("test");
        String code = null;
        if(StringUtils.isEmpty(code)) {
            redisTemplate.opsForValue().set("test", "code", Integer.valueOf("1"), TimeUnit.MINUTES);
        }
        String result = redisTemplate.opsForValue().get("test");
        System.out.println(result);
    }

    @RequestMapping("t2/{a}")
    void t2(@PathVariable String a){
        redisTemplate.opsForValue().set("address",a);

        String s = redisTemplate.opsForValue().get("address");
        System.out.println(s);
    }







}
